package gz.itcast.b_statement;

import gz.itcast.util.JdbcUtil;
import org.junit.Test;

import java.sql.Connection;
import java.sql.Statement;

/**
 * Created 吴海杰 on 2017/2/26.
 */
public class Demo1 {
    private String url = "jdbc:mysql://localhost:3306/day0224";
    private String user = "whj";
    private String password = "whj";
    Connection conn = null;
    Statement stmt = null;

    @Test
    public void test1() {
        try {
            //通过工具类获取连接
            conn=JdbcUtil.getConnection();
            stmt = conn.createStatement();
            String sql = "CREATE TABLE student1(id INT PRIMARY KEY AUTO_INCREMENT,name VARCHAR(20),gender VARCHAR(2));";
            int count = stmt.executeUpdate(sql);
            System.out.println("影响了" + count + "行!");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            /*
            if (stmt != null) {
            try {
            stmt.close();
            } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
            }
            }
            if ((conn != null))
            try {
            conn.close();
            } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
            }*/
            JdbcUtil.close(conn,stmt);
            }

        }
}
